package cn.javase.base.multithread._02_线程休眠与终止;

public class _03_线程终止 {

    public static void main(String[] args) {
        MyRunnable myRunnable = new MyRunnable();
        Thread t = new Thread(myRunnable);
        t.start();
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        myRunnable.stop();
    }

    private static class MyRunnable implements Runnable {

        public boolean isStop = false;

        @Override
        public void run() {
            for (int i = 1; !this.isStop; i++) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println(Thread.currentThread().getName() + "==>" + i);
            }
        }

        public void stop() {
            this.isStop = true;
        }

    }

}
